
#include "date.h"


Date::Date(int year, int month, int day)
{
	_year = year;
	_month = month;
	_day = day;
}

void Date::Print()
{
	cout << _year <<'-' << _month << '-' << _day << endl;
}


Date& Date::operator+=(int day)
{
	_day += day;
	while (_day > GetMonthDay(_year, _month))
	{
		_day -= GetMonthDay(_year, _month);
		++_month;
		if (_month == 13)
		{
			_year++;
			_month = 1;
		}
	}
	return *this;
}

Date Date::operator+(int day)
{
	Date tem = *this;
	tem += day;

	/*while (tem._day > GetMonthDay(tem._year, tem._month))
	{
		tem._day -= GetMonthDay(tem._year, tem._month);
		tem._month++;
		if (tem._month == 13)
		{
			tem._year++;
			tem._month = 1;
		}
	}*/
	return tem;
}

Date& Date::operator-=(int day)
{
	_day -= day;
	while (_day < 0)
	{
		_month--;
		if (_month == 0)
		{
			_year--;
			_month = 12;
		}
		_day += GetMonthDay(_year, _month);
	}
	return *this;
}

Date Date::operator-(int day)
{
	Date tem = *this;

	tem -= day;

	return tem;
}

int Date::operator-(const Date& d)
{

	return 1;

}
